package com.choosefine.it.project.service.Impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.choosefine.it.common.def.CommonConstant;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.common.exception.BusinessException;
import com.choosefine.it.project.dao.ProjectWorkerMapper;
import com.choosefine.it.project.model.ProjectWorkerInfo;
import com.choosefine.it.project.model.WorkerAttendanceDetail;
import com.choosefine.it.project.model.po.ProjectWorkerCondPO;
import com.choosefine.it.project.model.po.WorkerAttendancePO;
import com.choosefine.it.project.service.ProjectWorkerService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * 控制台-项目管理-工地数据管理 - 工人出勤 业务实现
 * 
 * @auth liaozhanggen 2016-12-10 上午11:04:50
 *
 */
@Service(value = "projectWorkerService")
public class ProjectWorkerServiceImpl implements ProjectWorkerService {

	@Autowired
	private ProjectWorkerMapper projectWorkerMapper;

	@Override
	public Page<ProjectWorkerInfo> queryProjectWorkerInfos(ProjectWorkerCondPO workerCondPO) throws BusinessException {
		if (StringUtils.isEmpty(workerCondPO.getProjectCode())) {
			throw new BusinessException(ResultCode.FAILED, CommonConstant.TEAM_RECRUITMENT_ID_IS_NULL);
		}

		// 分页
		PageHelper.startPage(workerCondPO.getPageNum(), workerCondPO.getPageSize());
		return projectWorkerMapper.queryProjectWorkerInfos(workerCondPO);
	}

	@Override
	public Page<WorkerAttendanceDetail> queryWorkerAttendDetailByUserCode(WorkerAttendancePO waPO)
			throws BusinessException {
		if (StringUtils.isEmpty(waPO.getUserCode()) || null == waPO.getRelationId()
				|| 0 == waPO.getRelationId().intValue()) {
			throw new BusinessException(ResultCode.FAILED, CommonConstant.TEAM_RECRUITMENT_ID_IS_NULL);
		}

		// 分页
		PageHelper.startPage(waPO.getPageNum(), waPO.getPageSize());
		Page<WorkerAttendanceDetail> result= projectWorkerMapper.queryWorkerAttendDetailByUserCode(waPO);
		return result;
	}

}
